Calculate the sum of the positive integers of N+(N-2)+(N-4)… (until N-x =< 0)¶
Calculate the sum of the positive integers of N+(N-2)+(N-4)… (until N-x =< 0).
Test Data:
sum_series(6) -> 12
sum_series(10) -> 30
def sum_series(N):
if N < 1:
return 0
else:
return N + sum_series(N - 2)
# test
print(sum_series(6)) # 12
print(sum_series(10)) # 30